package com.qgz.tools.statisics.db;

import android.util.Log;

import com.qgz.tools.statisics.entity.ProvinceAreaEntity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBManager {

    public void addProvince(ProvinceAreaEntity provinceEntity) {
        Connection conn = null;
        PreparedStatement st = null;
        ResultSet rs = null;
        try {
            // 获取连接
            conn = DBUtils.getConnection();
            // 编写sql
            String sql = "insert into tbl_province_area(code,name,level,parentId,typeCode) " +
                    "values (?,?,?,?,?)";
            // 创建语句执行者
            st = conn.prepareStatement(sql);
            //设置参数
            st.setString(1, provinceEntity.getCode());
            st.setString(2, provinceEntity.getName());
            st.setString(3, provinceEntity.getLevel());
            st.setString(4, provinceEntity.getParentId());
            st.setString(5, provinceEntity.getTypeCode());
            // 执行sql
            int i = st.executeUpdate();
            if (i == 1) {
                //Log.e("eee","数据添加成功！");
            } else {
                Log.e("eee",provinceEntity.getName() + "数据添加失败！");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            addProvince(provinceEntity);
        } finally {
            DBUtils.colseResource(conn, st, rs);
        }
    }
}
